<template>
  <div class="">
    <!-- 倒计时组件 -->
    <span>获取验证码{{time}}</span>
  </div>
</template>
<script setup lang="ts">
import { ref ,watch} from 'vue';
let time=ref<number>(5)
// 接受父组件的flag，控制显示与隐藏
let props= defineProps(['flag'])
let $emit=defineEmits(['getFlag'])
// 监听
watch(()=>props.flag.value,
()=>{
    let timer= setInterval(()=>{
            time.value--;
            if(time.value==0){
                $emit('getFlag',false)
                clearInterval(timer)
            }
    },1000)
},
{
    immediate:true,
})


</script>
<style lang="scss" scoped>




</style>
